package com.finalab.yueqiu.util;


import com.finalab.yueqiu.constant.RedisKeyType;
import com.finalab.yueqiu.exception.ParamIllegalException;

/**
 * 为了避免有key名字重复，故设置一个生成keyName的util
 */
public class RedisKeyUtil {

    private static final String SPILT = ":";
    private static final String BIZ_TOKEN = "TOKEN";
    private static final String BIZ_LIKE = "LIKE";
    private static final String BIZ_DISLIKE = "DISLIKE";
    private static final String EVENT_QUEUE = "EVENT_QUEUE";
    // 用户的粉丝列表的名称
    private static final String BIZ_FOLLOWER = "FOLLOWER";
    // 用户关注的类型的列表名称
    private static final String BIZ_FOLLOWEE = "FOLLOWEE";
    private static final String BIZ_AUTH = "AUTH";





    public static String getKey(RedisKeyType redisKeyType){
        switch (redisKeyType){
            case AUTH:
                return BIZ_AUTH;
            case EVENT:
                return EVENT_QUEUE;
            default:
                throw new ParamIllegalException("没有这种redisKey Type！");
        }
    }

    public static String getKey(int entityId, int entityType, RedisKeyType keyType){
         switch (keyType){
             case LIKE:
                 return get(BIZ_LIKE, entityId, entityType);
             case DISLIKE:
                 return get(BIZ_DISLIKE, entityId, entityType);
             case FOLLOWER:
                 return get(BIZ_FOLLOWER, entityId, entityType);
             case FOLLOWEE:
                 return get(BIZ_FOLLOWEE, entityId, entityType);
             case TOKEN:
                 return get(BIZ_TOKEN, entityId, entityType);
             default:
                 throw new ParamIllegalException("没有这种redisKey Type！");
         }
    }

    private static String get(String keyTypeName){
       return keyTypeName;

    }

    private static String get(String keyTypeName,int entityId, int entityType){
        StringBuilder builder = new StringBuilder();
        return builder
                .append(keyTypeName)
                .append(SPILT)
                .append(entityType)
                .append(SPILT)
                .append(entityId).toString();
    }


}
